/////////////////////////////////////////////////////////////////////////////
// Filename: Vector3h.h
// Description: 3D vector class of homogeneous coordinates
/////////////////////////////////////////////////////////////////////////////

#ifndef VECTOR3H_H
#define VECTOR3H_H

#include "Vector3.h"

class Vector3h {
public:
  float x,y,z,W; 
  
public:
  Vector3h():x(),y(),z(),W(1.0) {} //default is (0,0,0,1)
  Vector3h(float xx,float yy,float zz,float WW=1.0):x(xx),y(yy),z(zz),W(WW) {}
  Vector3h(const Vector3h &v):x(v.x),y(v.y),z(v.z),W(v.W) {}
  Vector3h(const Vector3 &v, float WW):x(v.x),y(v.y),z(v.z),W(WW) {}
  
  // [] operator to get elements
  float &operator [](int i) {return (&x)[i];}
  const float &operator [](int i) const {return (&x)[i];}
  
  // assignment operator
  Vector3h &operator=(const Vector3h &v) {x=v.x;y=v.y;z=v.z;W=v.W;return *this;}
  
  //cast from cartesian 3D vector, W=1
  Vector3h(const Vector3 &v):x(v.x),y(v.y),z(v.z),W(1.0) {}
  
  //cast to cartesian 3D vector. OBS! make sure to homogenize first!
  operator Vector3() const {return Vector3(x,y,z);}
  
  //divides with W, use this for display etc
  /*Vector3h &homogenize() {
    if (W!=0.0) {
      x/=W;
      y/=W;
      //z/=W; (nope! we wish to keep this for z-buffering)
      W=1.0;
    }
    return *this;
  } */ 
  
  //relation operators
  bool    operator ==(const Vector3h &p) const {return ((x==p.x)&&(y==p.y)&&(z==p.z)&&(W==p.W));}
  bool    operator !=(const Vector3h &p) const {return !((*this)==p);}
  
  
};


#endif 

/////////////////////////////////////////////////////////////////////////////
//                               END OF FILE                               //
/////////////////////////////////////////////////////////////////////////////
